<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\Collect as CollectModel;
use app\common\tool\Result;
use think\exception\ValidateException;

class Collect extends Base
{
    //我的收藏列表
    public function getList()
    {
        $param = $this->request->param();
        $map[]=['uid','=',$this->user->id];
        $map[]=['is_del','=',0];
        $list=CollectModel::getPageList($map, '*', $param['page'], 20, false, ['product']);
        return Result::success('获取成功！',$list);
    }
    //添加收藏
    public function addCollect()
    {
        try {
            $param = $this->request->post();
            $this->validate($param, 'Collect');
            return Result::fastReturn(CollectModel::addCollect($param,$this->user));
         } catch (ValidateException $e) {
             return Result::fail($e->getError());
         } catch (\Exception $e) {
             return Result::fail($e->getMessage());
         }
    }
    //取消收藏
    public function delCollect()
    {
        try {
            $param = $this->request->post();
            $this->validate($param, 'Collectdel');
            return Result::fastReturn(CollectModel::delCollect($param,$this->user));
         } catch (ValidateException $e) {
             return Result::fail($e->getError());
         } catch (\Exception $e) {
             return Result::fail($e->getMessage());
         }
    }
}